<?php
error_reporting(0);

require_once "../Helpdesk/theme.php";
require_once "../Common/database.php";
require_once "../Common/values.php";


$result1="SELECT * FROM tblJobs WHERE LogNumber LIKE '%$datelog%' ORDER BY LogNumber DESC";
$result = mysql_query($result1);
$logid = 1;
$dateloglimit = $datelog+1 ;
$dateloglimit=$dateloglimit.'0';
$row = mysql_fetch_array($result);
$_POST[due]=$_POST[dueday].'/'.$_POST[duemonth].'/'.$_POST[dueyear];

if ($date==$row['Date'])
{


$Log=$row['LogNumber']+1;
if ($Log==$dateloglimit)
{
$Log=$datelog.'10';
}
}
else
{
$Log=$datelog.$logid ;

}



$result="SELECT * FROM tblstatus WHERE Name='$_POST[status]'";
$row = mysql_fetch_array(mysql_query($result));
if ($_POST[requestor]!='')
{
$query="INSERT INTO tblJobs (LogNumber,Operator,Requestor,Subject,Time,Date,Proirty,Line,Status,Problem,Branch,Department,Phone,VNC,Due,Assigned,Closed,Private,Project,Screenshot,mail)
    VALUES ('$Log','$user','$_POST[requestor]','$_POST[subject]','$time','$date','$_POST[proirty]','$row[Line]','$_POST[status]','$_POST[problem]','$_POST[branch]','$_POST[department]','$_POST[phone]','$_POST[vnc]','$_POST[due]','$_POST[assigned]','','$_POST[private]','$_POST[project]','','$_POST[mailupdates]')";
mysql_query($query);
$query="INSERT INTO tblEvents (LogNumber,Date,Time,Operator,description,TimeS,`key`) VALUES ('$Log','$_POST[date]','$_POST[time]','$user','Created New Job','0','')";
mysql_query($query);

$_POST[mail]='new';
require "../Common/mail.php";
}
echo '<center><h2>Job Logged ';
echo '<p>Log number '; echo $Log;

echo '<p><a href="../index.php?f=helpdesk&p=hupdate&log='.$Log.'">Back to Job</a>';
echo '<p><a href="../index.php?p=hmy&f=helpdesk">Back to view jobs</a>';

$_POST[subject]='%'.$_POST[subject].'%';

echo '<p>Job Search<p></h2>';
$result = mysql_query("SELECT * FROM tblJobs where Subject LIKE '$_POST[subject]' ");
echo '<TABLE width="100%" cellpadding=0 border="1"  style="border: 1px solid #000000;">';
echo '<tr style="border: 1px solid #000000;"><td>Log Number</td><td>Due Date
</td><td>Assigned <br>to</td><td>Requestor</td><td>Subject</td><td>Proirty</td><td></td><td>Status</td></tr>';

while($row = mysql_fetch_array($result))
  {
   if($row[Closed]=='checked')
{
$row[Closed]='Closed';
}
else
{
$row[Closed]='Open';
}
  echo '<tr><td><a href="../index.php?f=helpdesk&p=hupdate&log='.$row['LogNumber'] .'">'.$row['LogNumber']. "</a></td><td>" . $row['Due'].'</td>'.'<td>'.$row[Assigned].'</td><td>'.$row['Requestor'].'</td><td>'.$row[Subject].'</td>'.'<td>'.$row[Proirty].'</td>'.'<td>'.'</td>'.'<td>'.$row[Status].'</td></tr>';
  }
echo '</TABLE>';

echo '<p><b>Archive Search</b><p></h2>';
$result = mysql_query("SELECT * FROM tbljobsarchive where Subject LIKE '$_POST[subject]' ");
echo '<TABLE width="100%" cellpadding=0 border="1"  style="border: 1px solid #000000;">';
echo '<tr style="border: 1px solid #000000;"><td>Log Number</td><td>Due Date
</td><td>Assigned <br>to</td><td>Requestor</td><td>Subject</td><td>Proirty</td><td></td><td>Status</td></tr>';

while($row = mysql_fetch_array($result))
  {
   if($row[Closed]=='checked')
{
$row[Closed]='Closed';
}
else
{
$row[Closed]='Open';
}
  echo '<tr><td><a href="../index.php?f=helpdesk&p=hupdatea&log='.$row['LogNumber'] .'">'.$row['LogNumber']. "</a></td><td>" . $row['Due'].'</td>'.'<td>'.$row[Assigned].'</td><td>'.$row['Requestor'].'</td><td>'.$row[Subject].'</td>'.'<td>'.$row[Proirty].'</td>'.'<td>'.'</td>'.'<td>'.$row[Status].'</td></tr>';
  }
echo '</TABLE>';
if($_FILES["file"]["name"]!='')
{

if (file_exists("screenshots/" . $_FILES["file"]["name"]))
      {
      echo "<h2><center>".$_FILES["file"]["name"] . " File already exists. </h2>";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "screenshots/" . $Log.'.jpeg');
	$_POST[file]=$_FILES["file"]["name"];
      echo "<h2><center>File uploaded Stored in: " . "screenshots/".$Log.'.jpeg</h2>';

      $query="UPDATE tblJobs SET screenshot='".$Log.".jpeg' WHERE LogNumber='".$Log."'";

mysql_query($query);
      }
}



$query="DELETE FROM tblJobs WHERE requestor=''";
mysql_query($query);




mysql_close();

exit;
?>